@extends('admin.layouts')
@section('css')
    <link href="{{asset('assets/css/bootstrap.min.css')}}" rel="stylesheet" />
    <link rel="stylesheet" href="{{asset('assets/css/font-awesome.min.css')}}" />
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />

    <!-- ace styles -->

    <link rel="stylesheet" href="{{asset('assets/css/ace.min.css')}}" />
    <link rel="stylesheet" href="{{asset('assets/css/ace-rtl.min.css')}}" />
    <link rel="stylesheet" href="{{asset('assets/css/ace-skins.min.css')}}" />
    <script src="{{asset('assets/js/ace-extra.min.js')}}"></script>

    {{--时间样式--}}
    <link rel="stylesheet" href="{{asset('assets/css/datepicker.css')}}" />
@endsection
@section('content')
    <div class="main-content">
        <div class="breadcrumbs" id="breadcrumbs">
            <script type="text/javascript">
                try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
            </script>

            <ul class="breadcrumb">
                <li>
                    <i class="icon-home home-icon"></i>
                    <a href="{{url('admin/index')}}">主页</a>
                </li>

                <li class="active">
                    普通用户管理
                </li>
            </ul><!-- .breadcrumb -->

            <div class="nav-search" id="nav-search">
                <form class="form-search">
								<span class="input-icon">
									<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
									<i class="icon-search nav-search-icon"></i>
								</span>
                </form>
            </div><!-- #nav-search -->
        </div>

        <div class="page-content">
            <div class="page-header">
                <h1>
                    普通用户管理
                    <small>

                    </small>
                </h1>
            </div><!-- /.page-header -->
            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <div class="row">
                        <form action="{{url('admin/userlist')}}" method="post">
                            <div class="col-xs-12 col-md-2">
                                <div class="input-group">
                                    <input class="form-control date-picker" value="{{$startTime}}" name="start_time" placeholder="开始创建时间" id="id-date-picker-1" type="text" data-date-format="yyyy-mm-dd" />
                                    <span class="input-group-addon">
                                        <i class="icon-calendar bigger-110"></i>
                                    </span>
                                </div>
                            </div>
                            {{csrf_field()}}
                            <div class="col-xs-12 col-md-2">
                                <div class="input-group">
                                    <input class="form-control date-picker" value="{{$endTime}}" name="end_time" placeholder="结束创建时间" id="id-date-picker-2" type="text" data-date-format="yyyy-mm-dd" />
                                    <span class="input-group-addon">
                                        <i class="icon-calendar bigger-110"></i>
                                    </span>
                                </div>
                            </div>

                            <div class="col-xs-12 col-md-2">
                                <div class="input-group">
                                    <select name="status" id="status" class="form-control">
                                        <option value="">选择账号状态</option>
                                        <option value="3"
                                        @if($status==3)
                                            selected=""
                                                @endif
                                        >未激活</option>
                                        <option value="1"
                                                @if($status==1)
                                                selected=""
                                                @endif
                                        >启用</option>
                                        <option value="2"
                                                @if($status==2)
                                                selected=""
                                                @endif
                                        >停用</option>
                                    </select>
                                    <span class="input-group-addon">
                                        <i class="icon-tag bigger-110"></i>
                                    </span>
                                </div>
                            </div>

                            <div class="col-xs-12 col-md-3">
                                <div class="input-group">
                                    <input type="text" name="username" id="username" class="form-control" value="{{$username}}" placeholder="输入用户名搜索..." />
                                    <span class="input-group-addon">
                                        <i class="icon-user bigger-110"></i>
                                    </span>
                                </div>
                            </div>

                            <div class="col-xs-12 col-md-3">
                                <div class="input-group">
                                    <input type="text" name="email" id="searchTitle" class="form-control search-query" value="{{$email}}" placeholder="输入email搜索..." />
                                <span class="input-group-btn">
                                    <button type="submit" class="btn btn-purple btn-sm">
                                        搜索
                                        <i class="icon-search icon-on-right bigger-110"></i>
                                    </button>
                                </span>
                                </div>
                            </div>
                        </form>
                    </div>
                    <hr>
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="table-responsive">
                                <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>用户名</th>
                                        <th>头像</th>
                                        <th>简介</th>
                                        <th>邮箱</th>
                                        <th>
                                            <i class="icon-time bigger-110 hidden-480"></i>
                                            创建时间
                                        </th>
                                        <th>
                                            <i class="icon-time bigger-110 hidden-480"></i>
                                            更新时间
                                        </th>
                                        <th class="hidden-480">状态</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @if(sizeof($allUser)>0)
                                        @foreach($allUser as $v)
                                            <tr id="id{{$v['id']}}">
                                                <td>{{$v['id']}}</td>
                                                <td>{{$v['username']}}</td>
                                                <td>
                                                    <img src="{{$v['avatar']}}-40X40" style="width: 25px;height: 25px;border: 1px solid #2e6589;" alt="avatar" data-rel="tooltip" data-placement="top" title="
                                                <img class='view' src='{{$v['avatar']}}-40X40' alt='images'  height='40px'>"
                                                </td>
                                                <td>{{$v['describe']}}</td>
                                                <td>{{$v['email']}}</td>
                                                <td>{{date('Y-m-d H:i:s',$v['created_at'])}}</td>
                                                <td>{{date('Y-m-d H:i:s',$v['updated_at'])}}</td>

                                                <td class="hidden-480">
                                                    @if($v['status']==1)
                                                        <span class="label label-sm label-success">
                                                        <i class="icon-ok bigger-120"></i>可用
                                                    </span>
                                                        @elseif($v['status']==3)
                                                        <span class="label label-sm label-danger">
                                                        <i class="icon-remove bigger-120"></i>未激活
                                                    </span>
                                                    @else
                                                        <span class="label label-sm label-danger">
                                                        <i class="icon-remove bigger-120"></i>停用
                                                    </span>
                                                    @endif

                                                </td>

                                                <td>
                                                    <div class="visible-md visible-lg hidden-sm hidden-xs btn-group">
                                                        @if($v['status']==2)
                                                            <a class="btn btn-xs btn-success" onclick="upstatus({{$v['id']}},1)" data-rel="tooltip" data-placement="top" title="账号启用">
                                                                <i class="icon-ok bigger-120"></i>
                                                            </a>
                                                        @elseif($v['status']==1)
                                                            <a class="btn btn-xs btn-danger"  onclick="upstatus({{$v['id']}},2)" data-rel="tooltip" data-placement="top" title="账号停用">
                                                                <i class="icon-remove bigger-120"></i>
                                                            </a>
                                                        @endif
                                                    </div>
                                                </td>
                                            </tr>
                                        @endforeach
                                    @else
                                        <tr>
                                            <td style="text-align: center" colspan="11">什么都没有啦</td>
                                        </tr>
                                    @endif
                                    </tbody>
                                </table>
                            </div><!-- /.table-responsive -->
                            {{$allUser->links()}}
                        </div><!-- /span -->
                    </div><!-- /row -->

                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.page-content -->
    </div><!-- /.main-content -->
    @endsection
@section('javascript')
    <script src='{{asset('assets/js/jquery-2.0.3.min.js')}}'></script>
    <script src="{{asset('assets/js/bootstrap.min.js')}}"></script>
    <script src="{{asset('assets/js/typeahead-bs2.min.js')}}"></script>

    <!-- ace scripts -->
    <script type="text/javascript" src="{{asset('assets/layer/layer.js')}}"></script>
    <script src="{{asset('assets/js/ace-elements.min.js')}}"></script>
    <script src="{{asset('assets/js/ace.min.js')}}"></script>

    {{--时间插件--}}
    <script src="{{asset('assets/js/date-time/bootstrap-datepicker.min.js')}}"></script>
    <script>
        $('[data-rel=tooltip]').tooltip({html:true});
        $('.date-picker').datepicker({autoclose:true}).next().on(ace.click_event, function(){
            $(this).prev().focus();
        });

        function upstatus(id,status){
            layer.load(2);
            $.post('{{url('admin/updateuserstatus')}}',{'_token':'{{csrf_token()}}','id':id,'status':status},function(res){
                layer.closeAll('loading');
                if(res.status){
                    layer.msg(res.msg);
                    sleep(2200);
                    location.href="{{url('admin/userlist')}}";
                }else{
                    layer.msg(res.msg);
                }
            });
        }

        function sleep(numberMillis) {
            var now = new Date();
            var exitTime = now.getTime() + numberMillis;
            while (true) {
                now = new Date();
                if (now.getTime() > exitTime)
                    return;
            }
        }
    </script>
    @endsection